import 'package:bxultimate/app/pages/application/organization/organization_attendance_management/widget/attendance.dart';
import 'package:bxultimate/app/pages/application/organization/organization_attendance_management/widget/attendance_analysis.dart';
import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/keep_alive.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class OrganizationAttendanceManagementPage extends StatefulWidget {
  const OrganizationAttendanceManagementPage({Key? key}) : super(key: key);

  @override
  State<OrganizationAttendanceManagementPage> createState() =>
      _OrganizationAttendanceManagementPageState();
}

class _OrganizationAttendanceManagementPageState
    extends State<OrganizationAttendanceManagementPage> {
  final controller = Get.find<OrganizationAttendanceManagementController>();
  final state = Get.find<OrganizationAttendanceManagementController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: TDNavBar(
          backgroundColor: Colors.transparent,
          title: "考勤管理",
          rightBarItems: [
            TDNavBarItem(
                iconWidget: const Icon(Icons.view_list),
                action: () {
                  Get.toNamed(RouterName.organizationAttendanceList,arguments: Get.arguments);
                }),
          ],
        ),
        body: _buildBody(),
      ),
    );
  }

  _buildBody() {
    return Obx(() => state.firstInit
        ? const Center(child: CircularProgressIndicator())
        : Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              TDTabBar(
                tabs: [
                  for (var item in state.tabs)
                    TDTab(
                      text: item.label,
                    )
                ],
                controller: controller.tabController,
                backgroundColor: Colors.transparent,
                showIndicator: true,
              ),
              Gaps.vGap8,
              Expanded(
                  child: TabBarView(
                controller: controller.tabController,
                children: [
                  KeepAliveWrapper(
                    child: Attendance(orgId: controller.orgId,),
                  ),
                  KeepAliveWrapper(
                    child: AttendanceAnalysis(orgId: controller.orgId,),
                  ),
                ],
              ))
            ],
          ));
  }

  @override
  void dispose() {
    Get.delete<OrganizationAttendanceManagementController>();
    super.dispose();
  }
}
